<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Css/btn.css">
    <link rel="stylesheet" href="../Css/new_addContract.css">
    <link rel="stylesheet" href="../bsp/css/bootstrap.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/c/font_3911564_ynvs5zhem7p.css">
</head>

<body>
    <div class="rightmain1">
        <div>
            <div>编辑合同</div>
            <div>
                <button type="submit" class="btn1 tijiaoabocun" onclick="xgcontract1()"><span
                        class="iconfont icon-export tijiaoabocun"></span>提交审核</button>
                <button type="submit" class="btn1 " onclick="xgcontract1()" id="baocunbtn"><span
                        class="iconfont icon-export"></span>保存</button>
                <button class="btn1"><a href="../contract/contractList.html"><span
                            class="iconfont icon-export"></span>返回</a> </button>
            </div>
        </div>
    </div>

    <div class="jibenxingxi">
        <div><span class="iconfont icon-sousuoxiao jbxx"></span><span>合同信息</span></div>
        <form action="">
            <ul>
                <li><span class="ispanWidth"><span>*</span>合同编号：</span><input type="text" value=""
                        id="contract_number1">
                </li>
                <li><span class="ispanWidth"><span>*</span>合同名称：</span><input type="text" value="" id="contract_name1">
                </li>
                <li><span class="ispanWidth"><span>*</span>合同日期：</span><input type="date" value="" id="contract_day1">
                </li>
                <!-- Modal -->
                <li><span class="ispanWidth"><span>*</span>客户名称：</span>
                    <input type="text" value="" id="Client_name1" data-toggle="modal" data-target="#myModal">
                    <Span class="iconfont icon-sousuoxiao spanwz1"></Span>
                    <!-- Modal -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true" class="XXX">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">客户选框</h4>
                                </div>
                                <div class="modal-body">
                                    <table>
                                        <div>
                                            <select name="hetongbianhao" id="">
                                                <option></option>
                                            </select>
                                            <input type="text" placeholder="请输入内容">
                                            <button type="button" class="btn1">查询</button>
                                            <button type="reset" class="btn1">重置</button>
                                        </div>
                                        <thead>
                                            <tr>
                                                <th>客户名称</th>
                                                <th>客户标签</th>
                                                <th>客户类型</th>
                                                <th>主要联系人</th>
                                                <th>手机号码</th>
                                            </tr>
                                        </thead>
                                        <tbody class="DataShow"></tbody>
                                    </table>
                                    <!-- 分页 -->
                                    <div class="modal-navigation"></div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn1 btn-default" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn1 btn-default" data-dismiss="modal">确定</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </li>
                <li><span class="ispanWidth"><span>*</span>所属商机：</span><input type="text" value=""
                        id="contract_opportunity1"></li>
                <li><span class="ispanWidth"><span>*</span>合同总金额（万元）：</span><input type="text" value=""
                        id="contract_amount1"></li>
                <li><span class="ispanWidth">合同内容：</span><textarea name="" id="" cols="30" rows="5"
                        id="contract_content1"></textarea>
                </li>
                <li><span class="ispanWidth">附件：</span>
                    <!-- <button class="dianjixiazai btn file" onclick="upload.click()"> -->
                    <!-- <span class="iconfont icon-yunshangchuan"></span>上传附件 -->
                    <input type="file" name="upload" accept=".jpg,.png,.pdf" id="contract_fj1" placeholder="上传附件">
                    <!-- </button> -->
                </li>
            </ul>
        </form>
    </div>

    <script>
        xgcontract();
        xgcontract1();
        displaytableDatakh();
        hqidr();



        //初始化数据
        function xgcontract() {
            console.log(1);
            let index;
            contract.forEach(e => {
                if (e.id == idtzm) {
                    index = e.id;
                }
            });
            // $('#name1').val('值');
            $("#contract_number1").val(contract[index - 1].contract_number);
            $("#contract_name1").val(contract[index - 1].contract_name);
            $("#contract_day1").val(contract[index - 1].contract_day);
            $("#Client_name1").val(contract[index - 1].Client_name);
            $("#contract_opportunity1").val(contract[index - 1].contract_opportunity);
            $("#contract_amount1").val(contract[index - 1].contract_amount);
            $("#contract_content1").val(contract[index - 1].contract_content);
        }



        //xiugai合同
        function xgcontract1() {
            console.log(1);
            let index;
            contract.forEach(e => {
                if (e.id == idtzm) {
                    index = e.id;
                }
            });
            // db.contract[index - 1].id = index;
            db.contract[index - 1].contract_number = $("#contract_number1").val();
            db.contract[index - 1].contract_name = $("#contract_name1").val();
            db.contract[index - 1].contract_day1 = $("#contract_day1").val();
            db.contract[index - 1].Client_name = cmval;
            db.contract[index - 1].contract_opportunity = $("#contract_opportunity1").val();
            db.contract[index - 1].contract_amount = $("#contract_amount1").val();
            db.contract[index - 1].contract_content = $("#contract_content1").val();
            db.contract[index - 1].contract_fj = $("#contract_fj1").val();

            // asyncLocalStory("contract");
            asyncLocalStory("contract");


        }


        //motaikuang
        function displaytableDatakh() {

            // $(".kehuchaxun").html('');
            // 文档碎片
            let fragment1 = document.createDocumentFragment();
            for (let i = 0; i < db.connection.length; i++) {
                // console.log(db.contract[0]);
                let tr = document.createElement("tr");

                tr.innerHTML = `
                    <td data-id=${db.connection[i].id} class="djuanze">${db.connection[i].name}</td>
                    <td>${db.connection[i].customer_label}</td>
                    <td>${db.connection[i].type}</td>
                    <td>${db.connection[i].linkman}</td>
                    <td>${db.connection[i].phone_number}</td>
                         `;

                fragment1.appendChild(tr);

            }

            $(".DataShow").append(fragment1);

        }


        var cmval;
        var idd;
        var cn;
        function hqidr() {
            // var cmval;
            $(".DataShow").on("click", ".djuanze", function (e) {
                idd = Number($(e.target).attr("data-id"));
                // console.log(idd);
                cn = db.connection[idd - 1].name;
                $("#Client_name1").val(cn);
                cmval = $("#Client_name1").val();

            });
        }





    </script>
</body>

</html>